#!/bin/sh
#!/bin/bash
#set -e
kills(){
    tpid_file=${1};
    tpid=`cat ${tpid_file}`
    if [[ ${tpid} ]]; then
        echo "Kill Process!${tpid}"
        kill -9 "${tpid}"
        rm -f "${tpid_file}"
    fi
}
#_param_artifactId="crm-generator"
#_param_debug_port="5006"
_param_artifactId=${1}
_param_debug_port=${2}
_BASE_PATCH=/app/crm/code/crm/crm-web/
_BASE_RUN_PATCH=/app/crm/manage-api/
cd "${_BASE_PATCH}/${_param_artifactId}" || exit
\cp "target/${_param_artifactId}.jar" "${_BASE_RUN_PATCH}/${_param_artifactId}/"
cd "${_BASE_RUN_PATCH}/${_param_artifactId}" || exit
kills "tpid"
#rm -rf app.log
nohup java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address="${_param_debug_port}" "${_param_artifactId}.jar" > app.log 2>&1 &
echo $! > tpid
